package com.system.fkjslee.hos;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class QueryActivity extends AppCompatActivity {

    private TextView tvPrePersonNum;
    private static Handler handler;
    private String prePersonNum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query);

        initView();
    }

    @SuppressLint("HandlerLeak")
    private void initView() {
        tvPrePersonNum = findViewById(R.id.tvPrePersonNum);


        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        if(!prePersonNum.equals("time run out"))
                            tvPrePersonNum.setText(prePersonNum);
                        break;
                }
            }
        };

        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();
                String param = "/prePersonNum?patientID=" + LogActivity.account;
                HttpThread httpThread = new HttpThread(LogActivity.url + "/prePersonName", param);
                httpThread.run();
                prePersonNum = httpThread.getResult();
                Message message = new Message();
                message.what = 1;
                handler.sendMessage(message);
                Looper.loop();
            }
        }).start();
    }
}
